import java.util.Arrays;
public class TestJava {
    public static void main(String[] args){
        int [] arry={1,2,3,4,5,6,7};
        String ret=myToString(arry);
        System.out.println(ret);
        System.out.println(findNum2(arry,2));
        }
    public static String myToString(int [] arry){
        if(arry==null){
            return null;
        }
        if(arry.length==0)
            return "[]";
        String ret ="[";
        for(int x: arry){
            ret+=x+" ";
        }
        ret+="]";
        return ret;
    }
//    查找数组指定元素(下标)
    public static int findNum2(int [] arry,int k){
        for (int i = 0; i < arry.length ; i++) {
            if(arry[i]==k){
                return i;
            }
        }
        return -1;
    }
//    二分查找
    public static int findNum1(int[] arry,int k){
        int left=0;
        int right=arry.length-1;
        while(left<right){
            int mid=(left+right)/2;
            if(arry[mid]<k){
                left=mid+1;
            }else if(arry[mid]>k){
                right=mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
//    冒泡排序
    public static void maopao(int[] arry){
        for(int i=0;i< arry.length-1;i++){
            boolean flg=false;
            for(int j=0;j< arry.length-1-i;j++){
                int temp=0;
                if(arry[j]>arry[j+1]){
                    temp=arry[j];
                    arry[j]=arry[j+1];
                    arry[j+1]=temp;
                    flg=true;
                }
            }
            if(flg==false){
                break;
            }
        }
    }
}
